home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_5.arc / VGA360.ASM < prev   
Assembly Source File  |  1989-06-11  |  6KB  |  216 lines

  1. ;
  2. ; *** Listing 1 ***
  3. ;
  4. ; Turbo C tiny/small/medium model-callable assembler
  5. ; subroutines to:
  6. ;    * Set 360x480 256-color VGA mode
  7. ;    * Draw a dot in 360x480 256-color VGA mode
  8. ;    * Read the color of a dot in 360x480 256-color VGA mode
  9.  
  10. ; Assembled with TASM 1.0.
  11. ;
  12. ; The 360x480 256-color mode set code and parameters were provided
  13. ; by John Bridges, who has placed them into the public domain.
  14. ;
  15. VGA_SEGMENT    equ    0a000h    ;display memory segment
  16. SC_INDEX    equ    3c4h    ;Sequence Controller Index register
  17. GC_INDEX    equ    3ceh    ;Graphics Controller Index register
  18. MAP_MASK    equ    2    ;Map Mask register index in SC
  19. READ_MAP    equ    4    ;Read Map register index in GC
  20. SCREEN_WIDTH    equ    360    ;# of pixels across screen
  21. WORD_OUTS_OK    equ    1    ;set to 0 to assemble for
  22.                 ; computers that can't handle
  23.                 ; word outs to indexed VGA registers
  24. ;
  25. _DATA    segment    public byte 'DATA'
  26. ;
  27. ; 360x480 256-color mode CRT Controller register settings.
  28. ; (Courtesy of John Bridges.)
  29. ;
  30. vptbl   dw      06b00h  ; horz total
  31.         dw      05901h  ; horz displayed
  32.         dw      05a02h  ; start horz blanking
  33.         dw      08e03h  ; end horz blanking
  34.         dw      05e04h  ; start h sync
  35.         dw      08a05h  ; end h sync
  36.         dw      00d06h  ; vertical total
  37.         dw      03e07h  ; overflow
  38.         dw      04009h  ; cell height
  39.         dw      0ea10h  ; v sync start
  40.         dw      0ac11h  ; v sync end and protect cr0-cr7
  41.         dw      0df12h  ; vertical displayed
  42.         dw      02d13h  ; offset
  43.         dw      00014h  ; turn off dword mode
  44.         dw      0e715h  ; v blank start
  45.         dw      00616h  ; v blank end
  46.         dw      0e317h  ; turn on byte mode
  47. vpend   label   word
  48. _DATA    ends
  49. ;
  50. ; Macro to output a word value to a port.
  51. ;
  52. OUT_WORD    macro
  53. if WORD_OUTS_OK
  54.     out    dx,ax
  55. else
  56.     out    dx,al
  57.     inc    dx
  58.     xchg    ah,al
  59.     out    dx,al
  60.     dec    dx
  61.     xchg    ah,al
  62. endif
  63.     endm
  64. ;
  65. _TEXT    segment byte public 'CODE'
  66.     assume    cs:_TEXT, ds:_DATA
  67. ;
  68. ; Sets up 360x480 256-color mode.
  69. ; (Courtesy of John Bridges.)
  70. ;
  71. ; Call as: void Set360By480Mode()
  72. ;
  73. ; Returns: nothing
  74. ;
  75.     public _Set360x480Mode
  76. _Set360x480Mode    proc    near
  77.     push    si        ;preserve C register vars
  78.     push    di
  79.         mov     ax,12h          ; start with mode 12h
  80.         int     10h             ; let the bios clear the video memory
  81.  
  82.         mov     ax,13h          ; start with standard mode 13h
  83.         int     10h             ; let the bios set the mode
  84.  
  85.         mov     dx,3c4h         ; alter sequencer registers
  86.         mov     ax,0604h        ; disable chain 4
  87.         out     dx,ax
  88.  
  89.         mov     ax,0100h        ; synchronous reset
  90.         out     dx,ax           ; asserted
  91.         mov     dx,3c2h         ; misc output
  92.         mov     al,0e7h         ; use 28 mHz dot clock
  93.         out     dx,al           ; select it
  94.         mov     dx,3c4h         ; sequencer again
  95.         mov     ax,0300h        ; restart sequencer
  96.         out     dx,ax           ; running again
  97.  
  98.         mov     dx,3d4h         ; alter crtc registers
  99.  
  100.         mov     al,11h          ; cr11
  101.         out     dx,al           ; current value
  102.         inc     dx              ; point to data
  103.         in      al,dx           ; get cr11 value
  104.         and     al,7fh          ; remove cr0 -> cr7
  105.         out     dx,al           ;    write protect
  106.         dec     dx              ; point to index
  107.         cld
  108.         mov     si,offset vptbl
  109.         mov     cx,((offset vpend)-(offset vptbl)) shr 1
  110. @b:     lodsw
  111.         out     dx,ax
  112.         loop    @b
  113.     pop    di        ;restore C register vars
  114.     pop    si
  115.     ret
  116. _Set360x480Mode    endp
  117. ;
  118. ; Draws a pixel in the specified color at the specified
  119. ; location in 360x480 256-color mode.
  120. ;
  121. ; Call as: void Draw360x480Dot(int X, int Y, int Color)
  122. ;
  123. ; Returns: nothing
  124. ;
  125. DParms    struc
  126.     dw    ?    ;pushed BP
  127.     dw    ?    ;return address
  128. DrawX    dw    ?    ;X coordinate at which to draw
  129. DrawY    dw    ?    ;Y coordinate at which to draw
  130. Color    dw    ?    ;color in which to draw (in the
  131.             ; range 0-255; upper byte ignored)
  132. DParms    ends
  133. ;
  134.     public _Draw360x480Dot
  135. _Draw360x480Dot    proc    near
  136.     push    bp    ;preserve caller's BP
  137.     mov    bp,sp    ;point to stack frame
  138.     push    si    ;preserve C register vars
  139.     push    di
  140.     mov    ax,VGA_SEGMENT
  141.     mov    es,ax    ;point to display memory
  142.     mov    ax,SCREEN_WIDTH/4
  143.             ;there are 4 pixels at each address, so
  144.             ; each 360-pixel row is 90 bytes wide
  145.             ; in each plane
  146.     mul    [bp+DrawY] ;point to start of desired row
  147.     mov    di,[bp+DrawX] ;get the X coordinate
  148.     shr    di,1    ;there are 4 pixels at each address
  149.     shr    di,1    ; so divide the X coordinate by 4
  150.     add    di,ax    ;point to the pixel's address
  151.     mov    cl,byte ptr [bp+DrawX] ;get the X coordinate again
  152.     and    cl,3    ;get the plane # of the pixel
  153.     mov    ah,1
  154.     shl    ah,cl    ;set the bit corresponding to the plane
  155.             ; the pixel is in
  156.     mov    al,MAP_MASK
  157.     mov    dx,SC_INDEX
  158.     OUT_WORD    ;set to write to the proper plane for
  159.             ; the pixel
  160.     mov    al,byte ptr [bp+Color]    ;get the color
  161.     stosb        ;draw the pixel
  162.     pop    di    ;restore C register vars
  163.     pop    si
  164.     pop    bp    ;restore caller's BP
  165.     ret
  166. _Draw360x480Dot    endp
  167. ;
  168. ; Reads the color of the pixel at the specified
  169. ; location in 360x480 256-color mode.
  170. ;
  171. ; Call as: int Read360x480Dot(int X, int Y)
  172. ;
  173. ; Returns: pixel color
  174. ;
  175. RParms    struc
  176.     dw    ?    ;pushed BP
  177.     dw    ?    ;return address
  178. ReadX    dw    ?    ;X coordinate from which to read
  179. ReadY    dw    ?    ;Y coordinate from which to read
  180. RParms    ends
  181. ;
  182.     public _Read360x480Dot
  183. _Read360x480Dot    proc    near
  184.     push    bp    ;preserve caller's BP
  185.     mov    bp,sp    ;point to stack frame
  186.     push    si    ;preserve C register vars
  187.     push    di
  188.     mov    ax,VGA_SEGMENT
  189.     mov    es,ax    ;point to display memory
  190.     mov    ax,SCREEN_WIDTH/4
  191.             ;there are 4 pixels at each address, so
  192.             ; each 360-pixel row is 90 bytes wide
  193.             ; in each plane
  194.     mul    [bp+DrawY] ;point to start of desired row
  195.     mov    si,[bp+DrawX] ;get the X coordinate
  196.     shr    si,1    ;there are 4 pixels at each address
  197.     shr    si,1    ; so divide the X coordinate by 4
  198.     add    si,ax    ;point to the pixel's address
  199.     mov    ah,byte ptr [bp+DrawX]
  200.             ;get the X coordinate again
  201.     and    ah,3    ;get the plane # of the pixel
  202.     mov    al,READ_MAP
  203.     mov    dx,GC_INDEX
  204.     OUT_WORD    ;set to read from the proper plane for
  205.             ; the pixel
  206.     lods    byte ptr es:[si] ;read the pixel
  207.     sub    ah,ah    ;make the return value a word for C
  208.     pop    di    ;restore C register vars
  209.     pop    si
  210.     pop    bp    ;restore caller's BP
  211.     ret
  212. _Read360x480Dot    endp
  213. _TEXT    ends
  214.     end
  215.  
  216.